package com.qf.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @author lixu
 */
@ControllerAdvice
@Component
public class GlobalException {

    public GlobalException() {
        System.out.println("====GlobalException");
    }

    /**
     * 处理异常
     * @param e
     * @return
     */
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String handlerArithmeticException(ArithmeticException e){
        //处理  打印日志
        return "方法出现了异常:" + e.getMessage();
    }
}
